#include "SyntaxHighlighterFactory.h"
#include "CppHighlighter.h"
#include "PasHighlighter.h"
#include "SqlHighlighter.h"
#include "HtmHighlighter.h"

QSyntaxHighlighter* SyntaxHighlighterFactory::create(const QString& key)
{
    QSyntaxHighlighter* ret = 0;
    QString name = key.toLower();
    if (name == QLatin1String("none")) {
        ret = 0;
    }
    else if (name == QLatin1String("cpp")) {
        ret = new CppHighlighter;
    }
    else if (name == QLatin1String("pas")) {
        ret = new PasHighlighter;
    }
    else if (name == QLatin1String("sql")) {
        ret = new SqlHighlighter;
    }
    else if (name == QLatin1String("htm")) {
        ret = new HtmHighlighter;
    }
    if (ret)
        ret->setObjectName(name);
    return ret;
}

QStringList SyntaxHighlighterFactory::keys()
{
    QStringList ret;
    ret << QLatin1String("none")
        << QLatin1String("cpp") << QLatin1String("pas")
        << QLatin1String("sql") << QLatin1String("htm");
    return ret;
}

QMap<QString, QVariant> SyntaxHighlighterFactory::info(const QString& key)
{
    QMap<QString, QVariant> ret;
    QString name = key.toLower();
    ret["key"] = QLatin1String("(unknown)");
    ret["text"] = QLatin1String("(Unknown)");
    if (name == QLatin1String("none")) {
        ret["key"] = name;
        ret["text"] = QLatin1String("None");
    }
    else if (name == QLatin1String("cpp")) {
        ret["key"] = name;
        ret["text"] = QLatin1String("C++");
    }
    else if (name == QLatin1String("pas")) {
        ret["key"] = name;
        ret["text"] = QLatin1String("Pascal");
    }
    else if (name == QLatin1String("sql")) {
        ret["key"] = name;
        ret["text"] = QLatin1String("Sql");
    }
    else if (name == QLatin1String("htm")) {
        ret["key"] = name;
        ret["text"] = QLatin1String("Html");
    }
    return ret;
}

QString SyntaxHighlighterFactory::fileFilter()
{
    return QObject::tr("All files (*.*);;"
                       "C/C++ files (*.cpp *.cxx *.h *.hpp *.c);;"
                       "Pascal files (*.pas *.dpr);;"
                       "SQL files (*.sql);;"
                       "HTML files (*.htm *.html *.xml)");
}
